﻿using System;
using static System.Console;

namespace VirtualMethods
{
    class Program
    {
        static void Main()
        {
            var r = new Rectangle();
            r.Position.X = 33;
            r.Position.Y = 22;
            r.Size.Width = 200;
            r.Size.Height = 100;
            r.Draw();
            //Rectangle实现了Draw方法，根据多态性，这里调用Rectangle的Draw方法
            //输出Rectangle with X: 33, Y: 22 and Width: 200, Height: 100
            DrawShape(r);

            r.Move(new Position { X = 120, Y = 40 });
            r.Draw();

            Shape s1 = new Ellipse();
            //Ellipse没有实现Draw方法，调用基类shape的Draw
            //输出Shape with X: 0, Y: 0 and Width: 0, Height: 0
            DrawShape(s1);
            ReadKey();

        }
        
        public static void DrawShape(Shape shape)
        {
            shape.Draw();//多态
        }
       

    }
}
